package com.demo.schedule;

public abstract class BaseTask implements Runnable {
  protected final String taskName;

  public BaseTask(String taskName) {
    this.taskName = taskName;
  }

  @Override
  public void run() {
    try {
      System.out.println("[" + taskName + "] 任务开始执行...");
      executeTask();
      System.out.println("[" + taskName + "] 任务执行完成");
    } catch (Exception e) {
      System.err.println("[" + taskName + "] 任务执行失败: " + e.getMessage());
      e.printStackTrace();
    }
  }

  protected abstract void executeTask() throws Exception;

  public String getTaskName() {
    return taskName;
  }
}
